package com.small.view.custview;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.smell.R;

public class SingleChoicePopWindow extends Dialog {
	protected ListView mListView;
	protected Button mButtonOK;
	protected Button mButtonCancel;
	 
	public TextView tite;
	Context ctx;
	protected SingleChoicAdapter singleChoicAdapter;

	public SingleChoicePopWindow(Context context) {
		super(context, R.style.CustomDialog);
		ctx = context;
	 
		setContentView(R.layout.choice_single_list_layout);
		mListView = (ListView) findViewById(R.id.listView1);
		Window window = getWindow();
		WindowManager.LayoutParams params = window.getAttributes();
		params.gravity = Gravity.CENTER;
		window.setAttributes(params);
		mButtonOK = (Button) findViewById(R.id.button_ok);
		mButtonCancel = (Button) findViewById(R.id.button_cancle);

	}

	public void initChoicePopWindow(String[] itmes,	String title) {
		singleChoicAdapter = new SingleChoicAdapter(this, ctx, itmes,R.drawable.selector_checkbox2);
		mListView.setAdapter(singleChoicAdapter);
		mListView.setOnItemClickListener(singleChoicAdapter);
		RelativeLayout rel = (RelativeLayout) findViewById(R.id.choiceHeader);
		if (title != null) {
			rel.setVisibility(View.VISIBLE);
			tite = (TextView) findViewById(R.id.choiceTitle);
			tite.setText(title);
			tite.setVisibility(View.VISIBLE);
		}else{
			rel.setVisibility(View.GONE); 
		}
	}

	public int getSelectItem() {		 
		return singleChoicAdapter.getSelectItem();
	}

}
